package com.example.espect.aspetcts;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.Resource;

/**
 * @Description
 * @Author ext.shengsongtao
 * @Date 2020-10-09 13:33
 */
@Component()
@Aspect
public class CustomAnnotationAspect {
    @Resource
    TransactionTemplate transactionTemplate;
    @Around("com.example.espect.aspetcts.pointcuts.NamePointcut.anyOldTransfer()")
    public Object process(ProceedingJoinPoint pjp) throws Throwable {

        System.out.println("before");
        Object proceed =transactionTemplate.execute(t->{
            Object proceedObj=null;
            try {
                proceedObj= pjp.proceed();
            } catch (Throwable throwable) {
                throwable.printStackTrace();
                t.setRollbackOnly();
            }
            return proceedObj;
        });
        System.out.println("end00");
        return proceed;
    }
}
